﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineAuction
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                LoadDuLieu();
        
        }
        private void LoadDuLieu()
        {
            if(Session ["username"]!=null)
            {
                string username = Request.QueryString["username"];
                OnlineAuctionDataContext tkdc = new OnlineAuctionDataContext();
                var acc = tkdc.Accounts.Where(tk => tk.Equals(this.txtuser.ToString())).First();

                this.txtuser.Text = acc.username.ToString();
                this.txtpass.Text = acc.password.ToString();
                this.txtfullname.Text = acc.fullname.ToString();
                this.txtemail.Text = acc.email.ToString();
                this.txtaddress.Text = acc.address.ToString();
                this.txtphone.Text = acc.phone.ToString();
            }
            else
            {
                Response.Redirect("login.aspx");
            }
        }
        protected void btnsave_Click(object sender, EventArgs e)
        {
            OnlineAuctionDataContext tkdc = new OnlineAuctionDataContext();
            var kt = tkdc.Accounts.Where(tk => tk.Equals(this.txtuser.ToString())).Count();
            Account acc = new Account();
            acc.username = this.txtuser.ToString();
            acc.password = this.txtpass.ToString();
            acc.fullname = this.txtfullname.ToString();
            acc.address = this.txtaddress.ToString();
            acc.email = this.txtemail.ToString();
            acc.phone = this.txtphone.ToString();

            tkdc.Accounts.InsertOnSubmit(acc);
            tkdc.SubmitChanges();
        }
      
    }
}